

def GetNextPosition(x, y, size_x, size_y):
    '''This method is used to get next index position in Key table'''
    if y >= (size_y-1):
        y = 0
        if x < (size_x - 1):
            x = x + 1
        else:
            return (-1, -1)
    else:
        y = y + 1

    return (x, y)


def GenerateKeyTable(keyword):
    '''Generate key table in Playfair algorithm
    '''
    LetterDict = { 'a': None, 'b': None, 'c': None, 'd': None, 'e': None, 'f': None, 'g': None, 'h': None, 'i': None, 'j': None, 'k': None, 'l': None, 'm': None, 
                      'n': None, 'o': None, 'p': None, 'q': None, 'r': None, 's': None, 't': None, 'u': None, 'v': None, 'w': None, 'x': None, 'y': None, 'z': None, }
    keyTable = [[0 for x in xrange(5)] for x in xrange(5)]

    i = 0
    j = 0

    for c in keyword:
        if LetterDict[c] is not None:
            keyTable[c] = (0, 0)
            nextPosition = GetNextPosition(i, j, 5, 5)
            i = nextPosition[0]
            j = nextPosition[1]

    #TODO: generate rest of key table 


def ChangePosition(x1, y1, x2, y2, size_x, size_y):
    '''Calculate ciphered character corrdatinates in key table according to Playfair algorithm'''
    if x1 == x2:
        y1 = (y1 + 1) % size_y
        y2 = (y2 + 1) % size_y
        return [(x1, y1), (x2, y2)]
    elif y1 == y2:
        x1 = (x1 + 1) % size_x
        x2 = (x2 + 1) % size_x
        return [(x1, y1), (x2, y2)]
    else:
        return [(x2, y1), (x1, y2)]



def Crypt(text, keyword):
    return text



def Decrypt(cipherText, originalCryptionShift):
    return cipherText


class PlayfairCipher(object):
    """description of class"""

    

